#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#

class Hello:
    hna = "xion"

    def world(self):
        print("world")


h1 = Hello()
h1.name = "xiong"

"""
print(hasattr(h1, "world"))   # True,  判断对象类是否存在
print(hasattr(h1, "World"))   # False

print(hasattr(h1, "name"))    # True   判断数据属性是否存在
print(hasattr(h1, "xxxx"))    # False

print(hasattr(Hello, "world"))      # 判断 类函数是否存在
print(hasattr(Hello, "hna"))        #  类属性是否存在


# 判断对象中是否有这个类
print(getattr(h1, "world"))     # <bound method Hello.world of <__main__.Hello object at 0x0000018C9FE9CAC8>>
print(getattr(h1, "world1", None))     # None ，如果不存在返回默认值

test = getattr(h1, "world")
test()      # world

"""

# 添加对象属性， 等于是 h1.age = 10000
setattr(h1, "age", 10000)  # setattr(x, 'y', v) is equivalent to ``x.y = v''
print(h1.__dict__)  # {'name': 'xiong', 'age': 10000}

# 删除对象属性， 等于是 del h1.age
delattr(h1, "age")  # delattr(x, 'y') is equivalent to ``del x.y''
print(h1.__dict__)  # {'name': 'xiong'}


